<?php

/**
 * Validator
 * 
 * @author littlexiang
 * @version $Id: Validator.php 54 2009-07-15 11:48:07Z littlexiang521 $
 */
class Validator {
    private $_result;
    private $_finalResult;
    private $_errors;
    private $_stack;
    
    public function __construct ($data) {
        $this->_result = true;
        $this->_finalResult = true;
    }
    
    public function getErrors () {
        return $this->_errors;
    }

    public function isValid($value){
        foreach ($this->_stack as $validator){
            $this->_result = $validator->isValid($value);
            $this->_errors[] = $validator->getError();
            $this->_finalResult = $this->_result && $this->_finalResult;
        }
        return $this->_finalResult;
    }
    
    public function addValidator($obj){
        $this->_stack[] = $obj;
    }

}
?>